import { createRouter, createWebHistory } from "vue-router";
import mineRoutes from "./mine.js";
import loginRoutes from "./login.js";
import communityRoutes from "./community.js";
import { accessChecking } from "./utils.js";

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  scrollBehavior: (to, from, savePosition) => {
    if (savePosition) {
      return savePosition;
    } else {
      return {
        top: 0,
      };
    }
  },
  routes: [
    {
      path: "/",
      redirect: "/home",
    },
    {
      path: "/home",
      name: "home",
      component: () => import("@/views/home/HomePage/HomePage.vue"),
      meta: { 
        tabbar: "home",
        title: "首页",
     },
    },
    {
      path: "/lecturer",
      name: "Lecturer",
      component: () => import("@/views/lecturer/Lecturer.vue"),
      meta: {
        title: "讲师中心",
      }
    },
    {
      path: "/lecturer-center",
      name: "LecturerCenter",
      component: () => import("@/views/lecturer-center/LecturerCenter.vue"),
      meta: {
        title: "讲师资料",
      }
    },
    {
      path: "/new-employee",
      name: "NewEmployee",
      component: () => import("@/views/new-employee/NewEmployee.vue"),
      meta: {
        title: "新员工专属",
      }
    },
    {
      path: "/exam-detail",
      name: "ExamDetail",
      component: () => import("@/views/exam-detail/ExamDetail.vue"),
      meta: {
        title: "考试详情",
      }
    },
    {
      path: "/task-detail",
      name: "TaskDetail",
      component: () => import("@/views/task-detail/TaskDetail.vue"),
      meta: {
        title: "任务详情", //新员工专属_任务详情
      }
    },
    {
      path: "/exam",
      name: "Exam",
      component: () => import("@/views/exam/Exam.vue"),
      meta: {
        title: "考试纪录", //新员工专属_任务详情_考试详情_考试纪录
      }
    },
    {
      path: "/study-plan",
      name: "StudyPlan",
      component: () => import("@/views/study-plan/StudyPlan.vue"),
      meta: {
        title: "学习计划", //学习计划
      }
    },
    {
      path: "/study-detail",
      name: "StudyDetail",
      component: () => import("@/views/study-detail/StudyDetail.vue"),
      meta: {
        title: "任务详情", //学习计划_任务详情
      }
    },
    {
      path: "/course-detail",
      name: "CourseDetail",
      component: () => import("@/views/course-detail/CourseDetail.vue"),
      meta: {
        title: "课程详情", //学习计划_课程详情
      }
    },
    {
      path: "/exam-rate",
      name: "ExamRate",
      component: () => import("@/views/exam-rate/ExamRate.vue"),
      meta: {
        title: "考试排行", //学习计划_任务详情_考试排行
      }
    },
    {
      path: "/test",
      name: "Test",
      component: () => import("@/views/test/Test.vue"),
      meta: {
        title: "考试中心", //考试中心-开考试结束
      }
    },
    {
      path: "/test-result",
      name: "TestResult",
      component: () => import("@/views/test-result/TestResult.vue"),
      meta: {
        title: "考试中心", //考试中心-开考试结束
      }
    },
    {
      path: "/find",
      name: "Find",
      component: () => import("@/views/find/index.vue"),
      meta: {
        title: "发现", //发现
      }
    },
    {
      path: "/lottery",
      name: "Fine",
      component: () => import("@/views/find/lottery/index.vue"),
      meta: {
        title: "幸运抽奖", //发现
      }
    },
    {
      path: "/elite",
      name: "Elite",
      component: () => import("@/views/elite/index.vue"),
      meta: {
        title: "精英", //发现
      }
    },
    {
      path: "/study-notes",
      name: "StudyNotes",
      component: () => import("@/views/study-notes/index.vue"),
      meta: {
        title: "学习笔记", //发现
      }
    },
    {
      path: "/course-notes",
      name: "CourseNotes",
      component: () => import("@/views/study-notes/course-notes.vue"),
      meta: {
        title: "课程笔记", //课程笔记
      }
    },
    {
      path: "/notes-detail",
      name: "NotesDetail",
      component: () => import("@/views/study-notes/notes-detail.vue"),
      meta: {
        title: "笔记详情", //课程笔记
      }
    },
    {
      path: "/registration",
      name: "Registration",
      component: () => import("@/views/registration/index.vue"),
      meta: {
        title: "报名中心", //报名中心
      }
    },
    {
      path: "/registration-detail",
      name: "RegistrationDetail",
      component: () => import("@/views/registration/registration-detail.vue"),
      meta: {
        title: "报名详情", //报名详情
      }
    },
    {
      path: "/company",
      name: "Company",
      component: () => import("@/views/registration/company.vue"),
      meta: {
        title: "公司内刊", //公司内刊
      }
    },
    {
      path: "/company-detail",
      name: "CompanyDetail",
      component: () => import("@/views/registration/company-detail.vue"),
      meta: {
        title: "内刊详情", //内刊详情
      }
    },
    {
      path: "/knowledge",
      name: "Knowledge",
      component: () => import("@/views/registration/knowledge.vue"),
      meta: {
        title: "知识资源库", //知识资源库
      }
    },
    {
      path: "/knowledge-detail",
      name: "KnowledgeDetail",
      component: () => import("@/views/registration/knowledge-detail.vue"),
      meta: {
        title: "资源详情", //资源详情
      }
    },
    {
      path: "/assignment",
      name: "Assignment",
      component: () => import("@/views/assignment/index.vue"),
      meta: {
        title: "作业中心", //作业中心
      }
    },
    {
      path: "/assignment-detail",
      name: "AssignmentDetail",
      component: () => import("@/views/assignment/assignment-detail.vue"),
      meta: {
        title: "作业详情", //作业详情
      }
    },
    {
      path: "/assignment-detail-file",
      name: "AssignmentDetailFile",
      component: () => import("@/views/assignment/assignment-detail-file.vue"),
      meta: {
        title: "作业详情", //作业详情
      }
    },
    {
      path: "/home-work",
      name: "HomeWork",
      component: () => import("@/views/assignment/home-work.vue"),
      meta: {
        title: "我的作业", //我的作业
      }
    },
    {
      path: "/assignment-examine",
      name: "AssignmentExamine",
      component: () => import("@/views/assignment/assignment-examine.vue"),
      meta: {
        title: "作业审批", //我的作业
      }
    },
    {
      path: "/live-history",
      name: "LiveHistory",
      component: () => import("@/views/live/live-history.vue"),
      meta: {
        title: "历史直播", //历史直播
      }
    },
    ...loginRoutes,
    ...mineRoutes,
    ...communityRoutes,
  ],
});

router.beforeEach(async (to, from) => {
  return await accessChecking(to, from);
});

export default router;
